package com.taotao.manage.controller.api;

import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.taotao.common.bean.ItemCatResult;
import com.taotao.manage.service.ItemCatService;

/**
 * 对外提供的关于 商品分类的接口
 * @author Beck
 *
 */
@Controller
@RequestMapping("api/item/cat")
public class APIItemCatController {
	@Autowired
	private ItemCatService itemCatService;
	
	private static Logger LOGGER = org.slf4j.LoggerFactory.getLogger(APIItemCatController.class);
	
	
	/**
	 * 返回所有的商品分类信息
	 * 参数：无
	 * 返回值: ItemCatData
	 */
	@RequestMapping("all")
	public ResponseEntity<ItemCatResult> queryItemCat(@RequestParam(value="callback", required=false)String callback){
		if (LOGGER.isInfoEnabled()){
			// 如果是info级别的
			LOGGER.info("传入的参数是: {}",callback);
		}
		try {
			// 调用service进行查询数据结果
			ItemCatResult result = itemCatService.queryItemCatAllToTree();
			if (LOGGER.isDebugEnabled()){
				LOGGER.debug("查询成功: {}", result);
			}
			return ResponseEntity.status(HttpStatus.OK).body(result);
		} catch (Exception e) {
			e.printStackTrace();
			if (LOGGER.isErrorEnabled()){
				LOGGER.error("出现异常: ", e);
			}
		}
		// 500
		return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
	}
}
